<?php
defined('_JEXEC') or die('Restricted access');
//echo "<pre>";print_r($this->lists_lucky_number);
?>

<script type="text/javascript">
<!--
	jQuery().ready(function(){
		jQuery.noConflict();
		jQuery("#list_lnum").click(function(){
			jQuery("#project_id").css('margin-top','8px');
			jQuery("#club_id").css('margin-top','8px');
			jQuery("#member_id").css('margin-top','8px');
			jQuery("#generate_code").css('margin-top','8px');
			//jQuery("#list_lnum").css('margin-top','8px');
			
			if(jQuery("#tbl_list_num").hasClass('display_none')){
				jQuery("#tbl_list_num").removeClass('display_none');
				jQuery("#tbl_list_num").addClass('display');
			}else{
				jQuery("#tbl_list_num").removeClass('display');
				jQuery("#tbl_list_num").addClass('display_none');
			}
		});
		/*
			var member_id = jQuery("#member_id").val();
			
			jQuery.ajax({
				url: "index.php?option=com_wrd&controller=profile&task=apply",
				type: "POST",
				data: "member_id="+member_id,
			});
		*/
		jQuery("#renew").click(function(){
			jQuery.ajax({
				url: "index.php?option=com_wrd&task=renewMember",
				dataType: "text",
				success: function (res) {
					jQuery("#member_id").val(res);
				}
			});
		});
		jQuery(".lucky_num").click(function(){
		
			jQuery("#member_id").val(jQuery(this).html()) ;
			jQuery('#email1').val(jQuery(this).html()) ;
			
			if(jQuery("#tbl_list_num").hasClass('display_none')){
				jQuery("#tbl_list_num").removeClass('display_none');
				jQuery("#tbl_list_num").addClass('display');
			}else{
				jQuery("#tbl_list_num").removeClass('display');
				jQuery("#tbl_list_num").addClass('display_none');
			}
		});
		jQuery("#generate_code").click(function(){
	 		jQuery.ajax({
				url: "index.php?option=com_wrd&task=generateMemberId",
				type: "POST",
				data: "",
				success: function (res) {
					jQuery('#member_id').val(res);
					jQuery('#email1').val(res);
					Joomla.submitbutton('apply');
				}
			});
			
	 	});
		jQuery("table tr.tr_lnum td").mouseover(function() {
			jQuery(this).parent().addClass("tr_hascolor") ;
			jQuery(this).addClass("td_hascolor") ;
		}).mouseout(function(){
			jQuery(this).parent().removeClass("tr_hascolor") ;
			jQuery(this).removeClass("td_hascolor") ;
		});
		jQuery('div#form_account div.pane-sliders').css('margin','0') ;
	});
	function loadLuckynum(limitstart){
		jQuery.post("index.php?option=com_wrd&controller=profile&layout=lnum&tmpl=component", {start: ""+limitstart+""}, function(data){
			if(data.length >0) {
				jQuery('#td_list_lucky_num').html(data);
			}
		});	
	}
//-->
</script>
<div class="col width-100">
	<table width="100%" cellpadding='0' cellspacing='0'>
		<tr>
			<td valign='top'>
				<table cellpadding='0' cellspacing='0'>
					<!--
					<?php if(empty($this->data->member_id)):?>
					<tr>
						<td colspan='2'><?php echo 'The fields <b style="color: #FF0000 ; padding: 0px 5px ;">*</b> are <b style="color: #FF0000 ; padding: 0px 5px ;">required</b>.' ;?></td>
					</tr>
					<?php endif;?>
					-->
					<tr style='display: none;'>
						<td class="key">
							<label for="title"><?php echo JText::_('Email ( Username )')?></label>
						</td>
						<td>
							<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->username; ?>" id="email1" name="email1" class="user_email"/> 
							<?php echo '<b style="color: #FF0000 ;  padding: 0px 5px ;">*</b>' ;?>
						</td>
					</tr>
					<?php 
						$pass_style = 'display: none;' ;
						$g_pass_word = empty($this->g_pass) ? '' : $this->g_pass ;
					?>
					<?php if(empty($this->data->id)):?>
					<tr style="<?php echo $pass_style ; ?>">
						<td class="key">
							<label for="title"><?php echo JText::_('Password')?></label>
						</td>
						<td>
							<input type="password" autocomplete="off" title="type" maxlength="50" size="50" value="<?php echo $g_pass_word ;?>" id="password1" name="password1" class="user_pass"/>
						</td>
					</tr>
					<tr style="<?php echo $pass_style ; ?>">
						<td class="key">
							<label for="title"><?php echo JText::_('Password Cofirmation')?></label>
						</td>
						<td>
							<input type="password" autocomplete="off" title="type" maxlength="50" size="50" value="<?php echo $g_pass_word ;?>" id="password2" name="password2" class="user_pass_confirm"/>
						</td>
					</tr>
					
					<?php endif; ?>
            		<tr>
						<td width="200"><strong>Latest Modify By:  <?php echo $this->modify->name; ?></strong></td>
						<td><strong>Latest Modify Date:</strong> <?php if(isset($this->data->modify_date)) echo date("d-m-Y",strtotime($this->data->modify_date));?><br /></td>
						
					</tr>
					<tr><td>
						Renew member ID:
					</td>
					<td>
						
						<?php if($this->data->renew == 'A'): ?>
							<!--<a href="index.php?option=com_wrd&task=renewCode&userid=<?php echo sha1($this->data->user_id);?>&id=<?php echo $this->data->id;?>" title="Renew Code">-->
							
								<input id="renew" style="cursor: pointer;font-weight: bold;border-radius: 5px;padding-top: 5px;padding-bottom: 5px;padding-left: 10px;padding-right: 10px;" type="button" class="subbutton" name="renew" value="Renew VIP number" />
							
							<!--</a>-->
						
						<?php else: ?>
						<input title="Done renew" style="background:#ccc !important;color: #000;font-weight: bold;border-radius: 5px;padding-top: 5px;padding-bottom: 5px;padding-left: 10px;padding-right: 10px;" type="button" class="subbutton" type="button" name="renew" value="Done" />
						<?php endif; ?>
						
						<!--<?php if($this->data->renew == 'A'): ?><input style="cursor: pointer;font-weight: bold;border-radius: 5px;padding-top: 5px;padding-bottom: 5px;padding-left: 10px;padding-right: 10px;" type="button" class="subbutton" name="renew" value="Renew VIP number" /><?php else: ?><input title="Done renew" style="background:#ccc;color: #000;font-weight: bold;border-radius: 5px;padding-top: 5px;padding-bottom: 5px;padding-left: 10px;padding-right: 10px;" type="button" class="subbutton" type="button" name="renew" value="Done" /><?php endif; ?>-->
						<!-- movie button -->
						<?php if(!empty($this->data->member_id)&&($this->data->renew == 'A')): ?>
			            			
				            			<style type="text/css">
											<--
											#list_lnum{
												background-color: #FFF ;
												cursor: pointer;
												float: left ;
	            							}
	            							.tr_hascolor{
												background-color: #E8F6FE ;
	            							}		            								            							
	            							.td_hascolor{
												background-color: #d0d0d0 ;
	            							}	            							
	            							.display_none{
												display: none;
	            							}
	            							#tbl_list_num{
	            								margin-top: 8px ;
											}
											#tbl_list_num tr.tr_lnum td.td_chan,#tbl_list_num tr.tr_lnum td.td_le,#tbl_list_num tr.tr_lnum td.td_first{
												border-right: 1px solid #d0d0d0 ;
											}											
											#tbl_list_num tr.tr_lnum td{
												border-bottom: 1px solid #d0d0d0 ;
											}
											#tbl_list_num tr td.lucky_num:hover{
												cursor: pointer;
	            							}
	            							.panel{
												width: 235px;
	            							}
											div.current input, div.current textarea, div.current select {
											    clear: none;
											    float: left;
											    margin: 5px 0 0 2px;
											}
											.lnum_prev,.lnum_next{
												cursor: pointer;
											}
											#form_account .pane-sliders{
												margin: 0 ;
											}
											-->
	            						</style>
			            				<input style='width:180px;margin-right: 10px;cursor:pointer;' type="button" name="list_lnum" id="list_lnum" class="subbutton list_lnum" value="Renew beautiful VIP number" title='or Select VIP Member ID for use' />
			            			</td>
			            			<td valign='top' width="220px" id='td_list_lucky_num'>
		            					<!-- start show lucky number -->
		            					<table id='tbl_list_num' style='border: 1px solid #d0d0d0 ;' cellspacing='0' cellpadding='2' class='display_none'>
											<tr class='tr_lnum tr_first'>
											<?php 
											$i = 0 ;
											$tr_type = 'tr_le' ;
											$td_type = '' ;
											$r = 1 ;
											foreach($this->lists_lucky_number as $lnum):
												if(($i!=0) && ($i%5 ==0)):
													$r++ ;
													if($r%2==0 && $r != 1):
														$tr_type = 'tr_chan' ;				
													else:
														$tr_type = 'tr_le' ;
													endif ;
													echo '</tr>';
													echo "<tr class='tr_lnum ".$tr_type."'>" ;
												endif;
												if($tr_type == 'tr_chan'):
													if($i%2==0 && $i != 0):
														$td_type = 'td_chan' ;
													else:
														if($i%5 == 0):
															$td_type = ' td_first' ;
														else:
															if(($i+1)%5 == 0):
																$td_type = ' td_last' ;
															else:
																$td_type = ' td_le' ;
															endif;
														endif;
													endif ;					
												else:
													if($i==0):
														$td_type = 'td_first ' ;
													else:
														if($i%2==0):
															if(($i+1)%5 == 0):
																$td_type = 'td_last' ;
															else:
																$td_type = ' td_le' ;
															endif;
														else:
															$td_type = 'td_chan' ;
														endif ;	
													endif;
												endif ;
												echo "<td class='lucky_num ".$td_type."'>".$lnum->text."</td>";
												$i++;
											endforeach;
											?>
											</tr>
											
											<?php if($this->total_lucky_number > 20):?>
											<tr>
												<td colspan='5'>
													<span style='float:left ;'>
													<?php if($this->total_lucky_number > 0 && $this->limitstart >= 20):?>
														<a class="lnum_prev" onclick="loadLuckynum(<?php echo intval($this->limitstart -20); ?>)">
														<img title="Prev" style="float: right ;" src="<?php echo JURI::base() .'/components/com_wrd/assets/images/prev.png'?>">
														</a>
													<?php endif; ?>
													</span>
													<span style='float:right ;'>
													<?php if($this->total_lucky_number > 20 && $this->limitstart >= 0 && intval($this->limitstart + 20) < $this->total_lucky_number):?>
														<a class="lnum_next" onclick="loadLuckynum(<?php echo abs(intval($this->limitstart + 20)) ; ?>)">
														<img title="Next" style="float: right ;" src="<?php echo JURI::base() .'/components/com_wrd/assets/images/next_items.png'?>">
														</a>
													<?php endif; ?>
													</span>
												</td>
											</tr>
											<?php endif ;?>
										</table>
										<!-- end show lucky number -->
			            			
			            			<?php endif; ?>
					
						<!-- End movie button -->
					</td>
					</tr>
					<tr>
	            		<td class="key" valign='top'>
	            			<label for="title"><?php echo JText::_('Member ID')?></label>
	            		</td>
            			<td>
            				<table width='100%' cellpadding='0' cellspacing='0'>
            					<tr>
            						<td valign='top'>
			            				<input type="text" title="pid" name="project_id" maxlength="2" size="2" value="1" id="project_id" />
			            				<input type="text" title="cid" name="club_id" maxlength="2" size="2" value="1" id="club_id" />
			            				<input type="text" title="type" maxlength="10" size="10" value="<?php echo $this->data->member_id; ?>" id="member_id" name="member_id" <?php if(isset($this->data->member_id)): ?>readonly="readonly"<?php endif; ?> class="member_id" /> 
				            			<?php if(empty($this->data->member_id)): ?>
			            					<input type="button" name="generate" value="generate code" id='generate_code' />
										<?php endif; ?>
            						</td>
            						<?php if(empty($this->data->member_id)): ?>
			            			<td width="20px" valign='top' align='left'>
				            			<style type="text/css">
											<--
											#list_lnum{
												background-color: #FFF ;
												cursor: pointer;
												float: left ;
	            							}
	            							.tr_hascolor{
												background-color: #E8F6FE ;
	            							}		            								            							
	            							.td_hascolor{
												background-color: #d0d0d0 ;
	            							}	            							
	            							.display_none{
												display: none;
	            							}
	            							#tbl_list_num{
	            								margin-top: 8px ;
											}
											#tbl_list_num tr.tr_lnum td.td_chan,#tbl_list_num tr.tr_lnum td.td_le,#tbl_list_num tr.tr_lnum td.td_first{
												border-right: 1px solid #d0d0d0 ;
											}											
											#tbl_list_num tr.tr_lnum td{
												border-bottom: 1px solid #d0d0d0 ;
											}
											#tbl_list_num tr td.lucky_num:hover{
												cursor: pointer;
	            							}
	            							.panel{
												width: 235px;
	            							}
											div.current input, div.current textarea, div.current select {
											    clear: none;
											    float: left;
											    margin: 5px 0 0 2px;
											}
											.lnum_prev,.lnum_next{
												cursor: pointer;
											}
											#form_account .pane-sliders{
												margin: 0 ;
											}
											-->
	            						</style>
			            				<input style='width:150px;' type="button" name="list_lnum" id="list_lnum" class="list_lnum" value="Renew beautiful VIP number" title='or Select VIP Member ID for use' />
			            			</td>
			            			<td valign='top' width="220px" id='td_list_lucky_num'>
		            					<!-- start show lucky number -->
		            					<table id='tbl_list_num' style='border: 1px solid #d0d0d0 ;' cellspacing='0' cellpadding='2' class='display_none'>
											<tr class='tr_lnum tr_first'>
											<?php 
											$i = 0 ;
											$tr_type = 'tr_le' ;
											$td_type = '' ;
											$r = 1 ;
											foreach($this->lists_lucky_number as $lnum):
												if(($i!=0) && ($i%5 ==0)):
													$r++ ;
													if($r%2==0 && $r != 1):
														$tr_type = 'tr_chan' ;				
													else:
														$tr_type = 'tr_le' ;
													endif ;
													echo '</tr>';
													echo "<tr class='tr_lnum ".$tr_type."'>" ;
												endif;
												if($tr_type == 'tr_chan'):
													if($i%2==0 && $i != 0):
														$td_type = 'td_chan' ;
													else:
														if($i%5 == 0):
															$td_type = ' td_first' ;
														else:
															if(($i+1)%5 == 0):
																$td_type = ' td_last' ;
															else:
																$td_type = ' td_le' ;
															endif;
														endif;
													endif ;					
												else:
													if($i==0):
														$td_type = 'td_first ' ;
													else:
														if($i%2==0):
															if(($i+1)%5 == 0):
																$td_type = 'td_last' ;
															else:
																$td_type = ' td_le' ;
															endif;
														else:
															$td_type = 'td_chan' ;
														endif ;	
													endif;
												endif ;
												echo "<td class='lucky_num ".$td_type."'>".$lnum->text."</td>";
												$i++;
											endforeach;
											?>
											</tr>
											
											<?php if($this->total_lucky_number > 20):?>
											<tr>
												<td colspan='5'>
													<span style='float:left ;'>
													<?php if($this->total_lucky_number > 0 && $this->limitstart >= 20):?>
														<a class="lnum_prev" onclick="loadLuckynum(<?php echo intval($this->limitstart -20); ?>)">
														<img title="Prev" style="float: right ;" src="<?php echo JURI::base() .'/components/com_wrd/assets/images/prev.png'?>">
														</a>
													<?php endif; ?>
													</span>
													
													<span style='float:right ;'>
													<?php if($this->total_lucky_number > 20 && $this->limitstart >= 0 && intval($this->limitstart + 20) < $this->total_lucky_number):?>
														<a class="lnum_next" onclick="loadLuckynum(<?php echo abs(intval($this->limitstart + 20)) ; ?>)">
														<img title="Next" style="float: right ;" src="<?php echo JURI::base() .'/components/com_wrd/assets/images/next_items.png'?>">
														</a>
													<?php endif; ?>
													</span>
												</td>
											</tr>
											<?php endif ;?>
										</table>
										<!-- end show lucky number -->
			            			</td>
			            			<?php endif; ?>
            					</tr>
            					
            				</table>
            			</td>
            		</tr>
            		<?php if($this->data->member_id > 149999):  ?>
            			<?php $data_meged = WrdHelper::checkMerged($this->data->member_id); if(!$data_meged):  ?>
	            		<tr>
	            			<td valign="top">Merger Profile</td>
	            			<td>
	            				<input type="text" name="merge_memberid" id="merge_memberid">
	            				<input onclick="mergeProfile()" type="button" name="mergerprofile" value="Preview Profile">
	            			</td>
	            		</tr>
	            		<tr>
	            			<td></td>
	            			<td>
	            				<div style="background-color: #D9EDF7;border-color: #BCE8F1;color: #3A87AD; margin: 5px;" id="preview_info">
	            				</div>
	            			</td>
	            		</tr>
	            		<?php else: ?>
	            		<tr>
	            			<td>Mergered Profile</td>
	            			<td>
	            				<?php echo  $data_meged->merge_member_id; ?>
	            			</td>
	            		</tr>	
	            		<?php endif; ?>
            		<?php endif; ?>
				</table>
			</td>
			<td width='120px' valign='top'>
				<div id='form_account'>
					<?php 
						if(!empty($this->filesalbum)){
							$style = 'style="display: none;"';
						}else{
							$style = '' ;
						}
					?>
					<div id='form_account_top' <?php echo $style ;?>>
						<input id="image_upload" name="audio_upload" type="file" />
					</div>
					<div id="imagefile">
						<div class="image_prview_pro">
							<?php 
								if(!empty($this->filesalbum)):
									if($this->filesalbum->type == 'profile'):
							?>
										<a style="position:absolute;right:-7px;top:-10px;" onclick="remove_image(<?php echo $this->filesalbum->id ;?>)" href="javascript:void(null)">
											<img src="<?php echo JURI::base(true).'/components/com_wrd/assets/images/remove.png'?>" />
										</a>
										<img width='100' height='100' src="<?php echo JURI::base(true).'/../wrd/thumb/'.$this->filesalbum->name ;?>" />
							<?php 
									endif;
								endif;
							 ?>
						</div>
					</div>
				</div>
			</td>
		</tr>
		
		<tr>
			<td colspan='2'>
				<a href="javascript:void(null)" onclick="resetPass()">
					<img width="120" alt="Reset Password" title="Reset Password" style="float: left ;" src="<?php echo JURI::base() .'components/com_wrd/assets/images/resetpass.jpg'?>">
				</a>
				<a href="javascript:void(null)" onclick="javascript:Joomla.submitbutton('apply')">
					<img title="Save & Next" style="float: right ;" src="<?php echo JURI::base() .'/components/com_wrd/assets/images/save_next.png'?>">
				</a>
			</td>
		</tr>
	</table>	
</div>
<script>
	function resetPass(){
		var form = document.adminForm ;
		form.task.value = 'resetPass' ;
		form.controller.value="profile" ;
		form.submit();
	}

	function mergeProfile(){
		var mid = jQuery('#merge_memberid').val();
		jQuery.ajax({
			url: "index.php?option=com_wrd&controller=profile&task=previewProflile&mid="+mid,
			type: "POST",
			data: "",
			success: function (res) {
				var obj = jQuery.parseJSON(res);
				jQuery('#preview_info').html('<div style="padding:35px;"><p><b>Member Name: </b>'+obj.f_name+' '+obj.l_name+'</p>'+'<p><b>Member Phone: </b>'+obj.phone+'</p>'+'<p><b>Member Email: </b>'+obj.p_email+'</p><p><input onclick="gomergeProfile()" type="button" name="gomergerprofile" value="Merge Profile"></p></div>');
			}
		});
	}
	
	function gomergeProfile(){
		var form = document.adminForm;
		form.task.value = 'mergeProfile';
		form.controller.value="profile" ;
		form.submit();
	}
	
</script>